<template>
  <div>
    <el-tree
      :data="data"
      :show-checkbox="JSON.parse(this.show)"
      default-expand-all
      node-key="id"
      ref="tree"
      highlight-current
      @check="choiseonly"
      @node-click="handleNodeClick"
      :props="defaultProps"
    >
    </el-tree>
  </div>
</template>
<script>
import axios from "axios";
export default {
  methods: {
    choiseonly(){
      this.choisevalue = this.$refs.tree.getCheckedKeys();
      console.log(this.choisevalue);
      this.$emit("call",this.choisevalue)

    },
      getCheckedKeys() {
    this.choisevalue = this.$refs.tree.getCheckedKeys();
      console.log(this.choisevalue);
    },
    handleNodeClick(data) {
         console.log(data);
         this.choisedValue = data;
         this.$emit("call",this.choisedValue,this.data)
    },
  },
  props:["oldmenus","isshow"],
  data() {
    return {
      data: [],
      defaultProps: {
        children: "menus",
        label: "menuname",
      },
      //用于菜单权限选择用的
      choisevalue:[],
      show:this.isshow,
      // 用于修改菜单用的
      choisedValue:{}
    };
  },
  //钩子函数
  created() {
      axios.get("rbacMenu/findAllMenu")
      .then((res)=>{
          this.data = res.data
      })
      .catch((err)=>{})
  },
  watch: {
      oldmenus:function(newValue,oldValue){
          this.choisevalue = newValue;
          this.$refs.tree.setCheckedKeys(this.choisevalue);
        //   this.choisevalue = newValue.menuids;
        console.log("新值",newValue)
      },
      isshow:function(newValue,oldValue){
          this.show = newValue;
        console.log("新值",newValue)
      },
  },
};
</script>